package com.pe1n.yangtaopai.view.activity;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.view.fragment.Order_AllCargoFragment;

import java.util.ArrayList;
import java.util.List;

public class OrderActivity extends AppCompatActivity {
    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private ImageView mImageView;
    private List<Fragment> mList;
    private FragmentManager fragmentManager;
    private MyViewPager mMyViewPager;
    private int reciveCount;
    private String[] arrStr=new String[]{
        "全部","待付款" ,"待发货" ,"待收货","已收货"
    };
    public OrderActivity() {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);
        Intent intent=getIntent();
        reciveCount=intent.getIntExtra("VP_INDEX",0);
        initData();
        initView();
    }

    private void initData() {
        mList=new ArrayList<>();
        for(int i=0;i<arrStr.length;i++){
            Fragment fragment=new Order_AllCargoFragment();
            mList.add(fragment);
        }
    }

    private void initView() {
        fragmentManager=getSupportFragmentManager();
        mMyViewPager=new MyViewPager( fragmentManager);
        mViewPager= (ViewPager) findViewById(R.id.activity_order_viewPager);
        mTabLayout= (TabLayout) findViewById(R.id.activity_order_tabLayout);
        mViewPager.setAdapter(mMyViewPager);
        mTabLayout.setupWithViewPager(mViewPager);
        mViewPager.setCurrentItem( reciveCount);
        mImageView= (ImageView) findViewById(R.id.activity_order_imageView_back);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


    }
    class MyViewPager extends FragmentPagerAdapter {
        public MyViewPager(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mList.get(position);
        }

        @Override
        public int getCount() {
            return mList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return arrStr[position];
        }
    }
}
